﻿<%@ Page validaterequest="false"  Language="C#" AutoEventWireup="true" CodeBehind="Article_inc.aspx.cs" Inherits="newBlog.CenterInc.view_inc.Article_inc" %>
<%@ Import Namespace="newBlog.CenterInc.Ctrltor" %>
<%@ Import Namespace="newBlog.CenterInc.tool" %>
<%  Response.ContentType = "application/json";
    if (Session["user_id"] == null) {
        Response.Write("{\"error\":\"您未登录本站\"}");
        return;
    }
    int mode = Request.QueryString["mode"] == null ? 0 : Convert.ToInt32(Request.QueryString["mode"]);//1修改审核状态 2删除文章,3发布文章,4移动分类
    string user_id = Session["user_id"].ToString();
    string article_id = Request.Form["article_id"]==null?"":Request.Form["article_id"];
    int grade = Convert.ToInt32(Session["user_grade"]);
    string title = Request.Form["title"]==null?"":Request.Form["title"];
    string content = Request.Form["content"]==null?"":Request.Form["content"];
    string time = Request.Form["time"]==null?"":Request.Form["time"];
    string catalog = Request.Form["catalog"]==null?"":Request.Form["catalog"];
    string price = Request.Form["price"]==null?"":Request.Form["price"];
    string PayContent = Request.Form["PayContent"]==null?"":Request.Form["PayContent"];
    string imgurl = Request.Form["url"]==null?"":Request.Form["url"];
    string describe = Request.Form["describe"]==null?"":Request.Form["describe"];
    string ispay = Request.Form["pay"]==null?"":Request.Form["pay"];
    Article_inc article_Inc = new Article_inc();
    isString isString = new isString();
    if (article_id.Length==0&&mode!=3) {
        Response.Write("{\"error\":\"您未给予任何文章的id\"}");
        return;
    }
    switch (mode) {
        case 1:
            if (article_Inc.isMyArticle(article_id,user_id)) {
                if (grade!=1) {
                    Response.Write("{\"error\":\"您不是该文章的作者，或者管理员\"}");
                    return;
                }
            }
            if (article_Inc.examine(article_id)) {
                Response.Write("{\"error\":\"删除失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"删除成功,您可在回收站内恢复文章。\"}");
            return;
        case 2:
            return;
        case 3:

            if (isString.isEmpty(title,content,time,catalog,imgurl,describe,ispay)) {
                Response.Write("{\"error\":\"请不要留空哦\"}");
                return;
            }
            if (ispay.Equals("open")) {
                if (isString.isEmpty(PayContent,price)) {
                    Response.Write("{\"error\":\"您了开启了收费内容，请不要留空哦\"}");
                    return;
                }
            }
            if (article_Inc.upArticle(title,isString.getfilterHtml(content),time,catalog,price,isString.getfilterHtml(PayContent),imgurl,describe,user_id)) {
                Response.Write("{\"error\":\"上传失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"上传成功\"}");
            return;
        case 4:
            if (isString.isEmpty(title,content,time,catalog,imgurl,describe,ispay)) {
                Response.Write("{\"error\":\"请不要留空哦\"}");
                return;
            }
            if (ispay.Equals("open")) {
                if (isString.isEmpty(PayContent,price)) {
                    Response.Write("{\"error\":\"您了开启了收费内容，请不要留空哦\"}");
                    return;
                }
            }
            if (article_Inc.modifyArticle(title,isString.getfilterHtml(content),time,catalog,price,isString.getfilterHtml(PayContent),imgurl,describe,article_id)) {
                Response.Write("{\"error\":\"修改失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"修改成功\"}");
            return;
        case 5:
            if (isString.isEmpty(catalog)) {
                Response.Write("{\"error\":\"请选择分类\"}");
                return;
            }
            if (article_Inc.movedirectory(article_id,catalog)) { 
                Response.Write("{\"error\":\"移动失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"移动成功\"}");
            return;
    }
    %>

